package com.h3bpm.kumhosunny.crm.controller.businesstravelreport;
/**
 * @Auther: Administrator
 * @Date: 2019/11/14 13:16
 * @Description:
 */

import OThinker.H3.Controller.ControllerBase;
import com.alibaba.fastjson.JSONObject;
import com.h3bpm.kumhosunny.common.utils.SqlUtil;
import data.DataRow;
import data.DataTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: businessTravelReportController
 * @Description: 描述 出差报告单手机端列表
 *
 * @author WJQ
 * @version V1.0
 * @Date
 */
@Controller
@RequestMapping("/Portal/CRM/businessTravelReport")
public class BusinessTravelReport extends ControllerBase {
    @Override
    public String getFunctionCode() {
        return null;
    }

    private static Logger log = LoggerFactory.getLogger(BusinessTravelReport.class);
    private  final String ONE="1";
    private  final String TOW="2";
    @RequestMapping("/getTravelReportList")
    @ResponseBody
    public JSONObject getBoList(String clientData, String state , String start) {
        log.info("移动端出差报告列表接口==================clientData=" + clientData);
        JSONObject result= new JSONObject();
        String userId =  getUserValidator().getUser().getCode();
        String userName =  getUserValidator().getUser().getName();
        String parentId =  getUserValidator().getUser().getManagerID();
        try {
        String sql ="SELECT  timeStar , customerName, workContest ,createPerson from i_businesstravelreport " +
                "  where 1=1 ";
        if(clientData != null &&  !"".equals(clientData)){
           sql += " and  createPerson like '%"+clientData+"%' OR  timeStar like '%"+clientData+"%' or workContest like '%"+clientData+"%' OR workContest LIKE '%"+clientData+"%'";
        }
        DataTable table = null;
           if(ONE.equals(state)) {
                sql += " and  createPerson  ='" + userName + "'  ORDER BY timeStar DESC ";
            }
        if(ONE.equals(state)) {
            sql += " and  appDatas  like '%" + userId + "%'  ORDER BY timeStar DESC ";
        }
        sql+="    limit  "+start+",10 ";

        table = SqlUtil.doQuery(sql);
            List<Map<String ,String >> list =new ArrayList<Map<String ,String > >();
            if(table!=null && table.getEntityRows()!=null && table.getEntityRows().size()>0) {
                for( DataRow dataRow :  table.getEntityRows()) {
                    Map<String, String> customerMap = new HashMap<String, String>(16);
                    String name=dataRow.getString("Name");
                    String timeStar=dataRow.getString("timeStar");
                    String customerName=dataRow.getString("customerName");
                    String workContest=dataRow.getString("workContest");
                    customerMap.put("Name",name);
                    customerMap.put("timeStar",timeStar);
                    customerMap.put("customerName",customerName);
                    customerMap.put("workContest",workContest);
                    list.add(customerMap);
                }
            }
            result.put("data",list);
            result.put("status","200");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
    @RequestMapping("/skipSoloTravelReportList")
    public String skipSoloList(){
        log.info("移动端出差报告列表接口个人========");
        return "redirect:/Portal/Mobile/kumhosunny/businesstravelreport.html?state=1";
    }


    @RequestMapping("/skipUnitTravelReportList")
    public String skipUnitLinkmanList(){
        log.info("移动端出差报告列表接口管理========");
        return "redirect:/Portal/Mobile/kumhosunny/businesstravelreport.html?state=2";
    }
}
